package com.caterina.activities;

import java.awt.Container;
import java.util.HashMap;
import java.util.TreeMap;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import com.caterina.activityManager.CActivity;
import com.caterina.components.COptionPane.MessageType;
import com.caterina.resources.CModels;
import com.caterina.resources.CWords;

import controllers.ManagerTask.TaskType;

public class TransactionStatsActivity extends CActivity {
	public TransactionStatsActivity(Container parent){
		super("TRANSACTION_STATS_ACTIVITY",parent);
	}
	@Override
	public void onStart() {
		this.putTask(TaskType.TRANSACTION_GET_STATS);
	}
	@Override
	@SuppressWarnings("unchecked")
	public void onData(TaskType task, Object data) {
		this.lastStats=(TreeMap<Integer, HashMap<String, Double>>) data;
		this.render();
	}

	@Override
	public void onError(TaskType task, Exception e) {
		this.showCOPtionPane(MessageType.ERROR, CWords.getWord(e.getMessage()));
	}
	private void render(){
		this.content=new JTextPane();
		content.setEditable(false);
		this.content.setContentType("text/html");
		this.content.setText(this.getHtml());
		contentScroll=new JScrollPane(content);
		this.add(contentScroll);
	}
	private String getHtml(){
		return CModels.getTransactionStatsModel(lastStats);
	}
	private TreeMap<Integer,HashMap<String,Double>> lastStats;
	private JTextPane content;
	private JScrollPane contentScroll;
	private static final long serialVersionUID = 1L;
}
